package com.vecharm.app.ui.smartlable

import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import com.ling.sdk.app.App
import com.ling.sdk.ui.BaseFragment
import com.vecharm.app.R
import com.vecharm.app.bean.Goods
import com.vecharm.app.bean.GoodsBean
import com.vecharm.app.utils.getGlide
import com.vecharm.app.utils.load
import com.vecharm.app.utils.url
import kotlinx.android.synthetic.main.fragment_decent_banner.*

class DecentBannerFragment : BaseFragment(), IAction {
    override fun preload(urls: ArrayList<String>?) {
        urls?.forEach { getGlide(App.app).load(it).preload() }
    }

    override fun onStartPlay() {
        decent_banner?.startAutoPlay()
    }

    override fun onPausePlay() {
        decent_banner?.stopAutoPlay()
    }

    override fun getLayoutId() = R.layout.fragment_decent_banner

    override fun onInitView() {

        val views = ArrayList<View>()

        val goods: Goods = arguments?.getSerializable("goods") as? Goods ?: Goods()

        goods.showUrl?.forEach {
            val imageView = ImageView(App.app)
            imageView.url(App.app, it)
            imageView.scaleType = ImageView.ScaleType.FIT_XY
            imageView.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
            views.add(imageView)
        }

        decent_banner.start(views, emptyList(),goods.bannerLoopInterval, goods.bannerAnimationDuration)
    }


}